
$(document).ready(function () {
	var win = window.dialogArguments;
	var url = "/schedule/queryClassroom";
	var j = 0;
	$.ajax({url:url, success:function (data) {
		$(data.root).each(function (i, classroom) {
			if ((i - 2) % 3 == 0) {
				j++;
				$("#data").append("<tr><td width='33%'><input type='radio' name='classroomId' value='" + data.root[i - 2].id + "-" + data.root[i - 2].teachingbuilding.teachingbuilding_name +"-"+ data.root[i - 2].name + "' />" + data.root[i - 2].teachingbuilding.teachingbuilding_name + "-" + data.root[i - 2].name + "(" + data.root[i - 2].number + ")</td>"+
								"<td width='34%'><input type='radio' name='classroomId' value='" + data.root[i - 1].id + "-" + data.root[i - 1].teachingbuilding.teachingbuilding_name +"-"+ data.root[i - 1].name + "' />" + data.root[i - 1].teachingbuilding.teachingbuilding_name + "-" + data.root[i - 1].name + "(" + data.root[i - 1].number + ")</td>"+
								"<td width='33%'><input type='radio' name='classroomId' value='" + data.root[i].id + "-" + data.root[i].teachingbuilding.teachingbuilding_name +"-"+ data.root[i].name + "' />" + data.root[i].teachingbuilding.teachingbuilding_name + "-" + data.root[i].name + "(" + data.root[i].number + ")</td></tr>");
			} else {
				if (data.root.length - 3 * j == 2) {
					$("#data").append("<tr><td width='33%'><input type='radio' name='classroomId' value='" + data.root[data.root.length - 2].id + "-" + data.root[data.root.length - 2].teachingbuilding.teachingbuilding_name +"-"+ data.root[data.root.length - 2].name + "' />" + data.root[data.root.length - 2].teachingbuilding.teachingbuilding_name + "-" + data.root[data.root.length - 2].name + "(" + data.root[data.root.length - 2].number + ")</td>"+
									 "<td width='34%'><input type='radio' name='classroomId' value='" + data.root[data.root.length - 1].id + "-" + data.root[data.root.length - 1].teachingbuilding.teachingbuilding_name +"-"+ data.root[data.root.length - 1].name + "' />" + data.root[data.root.length - 1].teachingbuilding.teachingbuilding_name + "-" + data.root[data.root.length - 1].name + "(" + data.root[data.root.length - 1].number + ")</td></tr>");
					return false;
				} else {
					if (data.root.length - 3 * j == 1) {
						$("#data").append("<tr><td width='34%'><input type='radio' name='classroomId' value='" + data.root[data.root.length - 1].id + "-" + data.root[data.root.length - 1].teachingbuilding.teachingbuilding_name +"-"+ data.root[data.root.length - 1].name + "' />" + data.root[data.root.length - 1].teachingbuilding.teachingbuilding_name + "-" + data.root[data.root.length - 1].name + "(" + data.root[data.root.length - 1].number + ")</li></td></tr>");
						return false;
					}
				}
			}
		});
	}});
	$("td").live("mouseover", function (event) {
		$(this).css("cursor", "pointer");
	});
	var revalue;
	$("#confirm").click(function () {
		var elems = $(":radio");
		var v = $(elems).each(function (i, elem) {
			if (elem.checked) {
				revalue = $(elem).attr("value");
			}
		});
		if (revalue == null || "" == revalue) {
			alert("\u8bf7\u9009\u62e9\u6559\u5ba4\uff01");
		} else {
			window.returnValue = revalue;
			window.close();
		}
	});
	$("#cancel").click(function () {
		window.close();
	});
});

